package com.woniu.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.entity.ExamItem;
import com.woniu.entity.Staff;
import com.woniu.entity.SurgeryItem;
import com.woniu.mapper.ExamItemMapper;
import com.woniu.service.ExamItemService;
import com.woniu.utils.ResponseEnum;
import com.woniu.utils.ResponseUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ExamItemServiceImpl implements ExamItemService {
    @Resource
    private ExamItemMapper examItemMapper;
    @Override
    public ResponseUtil selectAll(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<ExamItem> examItemList = examItemMapper.selectAll();
        PageInfo pageInfo = new PageInfo(examItemList);
        return examItemList != null ?ResponseUtil.get(ResponseEnum.OK,pageInfo)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }

    @Override
    public ResponseUtil updateExam(Integer id) {
        int rows = examItemMapper.updateExam(id);
        return rows == 1
                ? ResponseUtil.get(ResponseEnum.OK)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }

    @Override
    public ResponseUtil insertSelective(ExamItem record) {
        int rows = examItemMapper.insertSelective(record);
        return rows == 1
                ? ResponseUtil.get(ResponseEnum.OK, record)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }

    @Override
    public ResponseUtil updateByPrimaryKeySelective(ExamItem record) {
        int rows = examItemMapper.updateByPrimaryKeySelective(record);
        return rows == 1
                ? ResponseUtil.get(ResponseEnum.OK)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }

    @Override
    public ResponseUtil selectByCondition(String itemName, Integer status, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<ExamItem> examItemList = examItemMapper.selectByCondition(itemName,status);
        PageInfo pageInfo = new PageInfo(examItemList);
        return examItemList!=null ? ResponseUtil.get(ResponseEnum.OK,pageInfo)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }

    @Override
    public ResponseUtil findAll() {
        List<ExamItem> examItemList = examItemMapper.findAll();
        return examItemList != null ?ResponseUtil.get(ResponseEnum.OK,examItemList)
                :ResponseUtil.get(ResponseEnum.FAIL);
    }
}
